require('../css/my.less')
window.utils.namichref()
// -----------------------------------------
let uname = document.querySelector('header .top .showovrn p')
let showFile = document.querySelector('#showFile')
let shimg = document.querySelector('header .top .dataimg')
let showleft = document.querySelector('.showRun .left #showleft')
let showright = document.querySelector('.showRun .right #showright')
let datasbot = document.querySelector('header .bottom span')
let userID = JSON.parse(localStorage.getItem('users')).userId
// -----------------------------------------
//
window.$http.get(`/users/mysportsBadge?userId=${userID}`, function (res) {
    console.log(res)
	if (res.status === 0) {
        uname.textContent = res.data.user.nickname //渲染用户名
		datasbot.textContent = res.data.user.describe //渲染个人签名
		showleft.textContent =parseInt(res.data.sports.times)  //渲染时长
		showright.textContent =parseInt(res.data.sports.calorie)  //渲染卡路里
		if (res.data.user.imgurl) {
            shimg.src = window.$BASE_URL + res.data.user.imgurl //渲染图片
		}else{
            shimg.src=require('../img/headerPic.jpg')
        }
	}
})
// -----------------------------------------
//把file的事件绑定到img上
shimg.addEventListener('click', function () {
	showFile.click()
})
//点击input上传文件（图片）
showFile.addEventListener('change', function () {
	console.log(this.files)
	window.$updateFile(
		'/image/fileUpload',
		'imgurl',
		this.files[0],
		function (res) {
			if (res.status === 0) {
				window.$http.post(
					'/users/userEdit',
					{
						userId: userID,
						imgurl: res.data,
					},
					function (res1) {
						console.log(res1)
						if (res1.status === 0) {
							shimg.src = window.$BASE_URL + res.data
						}
					}
				)
			}
		}
	)
})

// -----------------------------------------
//退出登录

let Logout = document.querySelector('#Logout')
Logout.addEventListener('click', function () {
	localStorage.removeItem('users')
	location.reload()
})
window.utils.showuhdy(3)
